package net.maku.custom.biza.service.reveiveable.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.Date;
import java.util.List;
import lombok.AllArgsConstructor;
import net.maku.custom.biza.controller.reveiveable.query.ReceivePayDetailQuery;
import net.maku.custom.biza.controller.reveiveable.vo.ReceivePayDetailVO;
import net.maku.custom.biza.mapper.reveiveable.ReceivePayDetailConvert;
import net.maku.custom.biza.mapper.reveiveable.ReceivePayDetailDao;
import net.maku.custom.biza.pojo.reveiveable.ReceivePayDetailEntity;
import net.maku.custom.biza.service.reveiveable.ReceivePayDetailService;
import net.maku.framework.common.page.PageResult;
import net.maku.framework.common.service.impl.BaseServiceImpl;
import net.maku.framework.security.user.SecurityUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 收款明细
 *
 * @author NULL
 * @since 1.0.0 2022-07-13
 */
@Service
@AllArgsConstructor
public class ReceivePayDetailServiceImpl extends BaseServiceImpl<ReceivePayDetailDao, ReceivePayDetailEntity> implements
        ReceivePayDetailService {

    @Override
    public PageResult<ReceivePayDetailVO> page(ReceivePayDetailQuery query) {
        IPage<ReceivePayDetailEntity> page1 = getPage(query);
        List<ReceivePayDetailVO> receivePayDetailVOS = baseMapper.selectRelList(page1, query);
        return new PageResult<>(receivePayDetailVOS, page1.getTotal());
    }

    private QueryWrapper<ReceivePayDetailEntity> getWrapper(ReceivePayDetailQuery query){
        QueryWrapper<ReceivePayDetailEntity> wrapper = new QueryWrapper<>();

        return wrapper;
    }

    @Override
    public void save(ReceivePayDetailVO vo) {
        ReceivePayDetailEntity entity = ReceivePayDetailConvert.INSTANCE.convert(vo);
        entity.setCreator(SecurityUser.getUserId());
        entity.setCreateTime(new Date());
        baseMapper.insert(entity);
    }

    @Override
    public void update(ReceivePayDetailVO vo) {
        ReceivePayDetailEntity entity = ReceivePayDetailConvert.INSTANCE.convert(vo);
        entity.setUpdater(SecurityUser.getUserId());
        entity.setUpdateTime(new Date());
        updateById(entity);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {
        removeByIds(idList);
    }

}